package service

import (
	"ChinaDistrictCrawler/internal/model/entity"
	"ChinaDistrictCrawler/internal/service/internal/dao"
	"context"
)

type sCity struct{}

var insCity = sCity{}

func City() *sCity {
	return &insCity
}

// Create 创建内容
func (s *sCity) Create(ctx context.Context, in entity.City) (int, error) {
	_, err := dao.City.Ctx(ctx).Data(in).InsertAndGetId()
	if err != nil {
		return 0, err
	}
	return 1, nil
}

func (s *sCity) Info(ctx context.Context, id uint) (entity.City, error) {
	var result entity.City
	err := dao.City.Ctx(ctx).WherePri(id).Scan(&result)
	if err != nil {
		return result, err
	}
	return result, nil
}
